<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePolling extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 巡检任务
        if (!Schema::hasTable('polling')) {
            Schema::create('polling', function (Blueprint $table) {
                $table->id();
                $table->string('number', '64')->default('')->comment('巡检任务编号');
                $table->string('status', '32')->default('')->comment('状态');
                $table->unsignedInteger('customer_id')->default(0)->comment('客户ID');
                $table->string('customer_name')->default('')->comment('客户姓名');
                $table->unsignedInteger('customer_user_id')->default(0)->comment('客户联系人ID');
                $table->string('customer_user_name')->default('')->comment('客户联系人姓名');
                $table->string('customer_user_telephone')->default('')->comment('客户联系人电话');
                $table->string('customer_address')->default('')->comment('详细地址');
                $table->string('customer_sign')->default('')->comment('客户签名');
                $table->string('plan_at')->default('')->comment('计划开始时间');
                $table->text('description')->comment('描述信息');
                $table->unsignedInteger('user_id')->default(0)->comment('负责人ID');
                $table->string('user_name')->default('')->comment('负责人姓名');
                $table->unsignedInteger('create_user_id')->default(0)->comment('创建人ID');
                $table->string('create_user_name')->default('')->comment('创建人姓名');
                $table->unsignedTinyInteger('acted')->default(0)->comment('是否已执行巡检');
                $table->unsignedTinyInteger('exception')->default(0)->comment('是否异常');
                $table->string('start_at')->default('')->comment('实际开始时间');
                $table->string('complete_at')->default('')->comment('实际完成时间');
                $table->float('timeout_hour')->default(0)->comment('判定超时时间(小时)');
                $table->integer('create_time')->nullable();
                $table->integer('update_time')->nullable();
            });
        }

        if (!Schema::hasTable('polling_history')) {
            Schema::create('polling_history', function (Blueprint $table) {
                $table->id();
                $table->unsignedInteger('actor_id')->default(0)->comment('操作人ID');
                $table->string('actor_name', '64')->default('')->comment('操作人姓名');
                $table->unsignedInteger('to_actor_id')->default(0)->comment('被操作人ID');
                $table->string('to_actor_name', '64')->default('')->comment('被操作人姓名');
                $table->string('content')->default('')->comment('具体操作内容');
                $table->integer('create_time')->nullable();
                $table->integer('update_time')->nullable();
            });
        }

        // 巡检计划
        if (!Schema::hasTable('polling_plan')) {
            Schema::create('polling_plan', function (Blueprint $table) {
                $table->id();
                $table->string('number', '64')->default('')->comment('巡检计划编号');
                $table->string('name')->default('')->comment('巡检计划名称');
                $table->string('plan_start_at')->default('')->comment('计划开始时间');
                $table->string('plan_end_at')->default('')->comment('计划截止时间');
                $table->string('circle_unit')->default('')->comment('计划周期: 日、周、月');
                $table->unsignedInteger('circle_count')->default(0)->comment('周期单位内开始时间');
                $table->string('plan_at')->default('')->comment('计划开始时间');
                $table->unsignedInteger('create_user_id')->default(0)->comment('创建人ID');
                $table->string('create_user_name')->default('')->comment('创建人姓名');
                $table->unsignedInteger('polling_user_id')->default(0)->comment('巡检负责人ID');
                $table->string('polling_user_name')->default('')->comment('巡检负责人姓名');
                $table->unsignedInteger('polling_customer_id')->default(0)->comment('巡检客户ID');
                $table->string('polling_customer_name')->default('')->comment('巡检客户名称');
                $table->unsignedInteger('polling_customer_user_id')->default(0)->comment('巡检客户联系人ID');
                $table->string('polling_customer_user_name')->default('')->comment('巡检客户联系人姓名');
                $table->string('polling_customer_user_telephone')->default('')->comment('巡检客户联系人电话');
                $table->string('polling_customer_address')->default('')->comment('巡检客户地址');
                $table->string('polling_description')->default('')->comment('巡检任务描述');
                $table->integer('create_time')->nullable();
                $table->integer('update_time')->nullable();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

    }
}
